#include "deletewidget.h"
#include "ui_deletewidget.h"
#include"QErrorMessage"
#include<QDebug>
Deletewidget::Deletewidget(Graph *a,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Deletewidget)
{
    tmp=a;
    ui->setupUi(this);
    this->setWindowTitle("删除交通记录");
    ui->comboBox_type->addItem("列车");
    ui->comboBox_type->addItem("飞机");
    ui->comboBox_choose->addItem(" ");
}

Deletewidget::~Deletewidget()
{
    delete ui;
}

void Deletewidget::on_pushButton_clicked()
{
    if(ui->lineEdit_BG->text().isEmpty()||ui->lineEdit_LT->text().isEmpty()){
        QErrorMessage *dlg=new QErrorMessage(this);
        dlg->setWindowTitle("错误信息");
        dlg->showMessage("请填写上述信息！");
    }
    else{//筛选信息填入combobox
        ui->comboBox_choose->clear();
        bcity=ui->lineEdit_BG->text();
        lcity=ui->lineEdit_LT->text();
        type=ui->comboBox_type->currentIndex();
        vec=tmp->findTinfo(bcity,lcity,type);
        ui->comboBox_choose->addItem(" ");
        for(int i=0;i<vec.size();i++){
            ui->comboBox_choose->addItem(bcity+"->"+lcity+" "+vec[i]->b.to_text()+"-"+vec[i]->l.to_text()+" "+"票价"+QString::number(vec[i]->cost));
        }
    }
}

void Deletewidget::on_pushButton_OK_clicked()
{
    if(ui->comboBox_choose->currentIndex()==0){//错误弹窗
        QErrorMessage *dlg=new QErrorMessage(this);
        dlg->setWindowTitle("错误信息");
        dlg->showMessage("请先选择要编辑的交通信息！");
        return;
    }
    else{
        tmp->deletetfinfo(vec[ui->comboBox_choose->currentIndex()-1]);
        this->close();
    }
}

void Deletewidget::on_pushButton_cancel_clicked()
{
    this->close();
}
